home *** CD-ROM | disk | FTP | other *** search
/ Atari Mega Archive 1 / Atari Mega Archive - Volume 1.iso / printing / hc24_h12.arc / HC24_H12.C next >
C/C++ Source or Header  |  1992-02-15  |  7KB  |  215 lines

  1.  
  2. > The 2 files listings follows:
  3.  
  4.  
  5. > Beginning of file HC24_H12.H
  6. /* The prototypes */
  7. extern  void outchar (int c);
  8. extern  void outchars (char *str);
  9. > End of file HC24_H12.H
  10.  
  11.  
  12. > Beginning of file HC24_H12.C
  13. /*
  14.  * HC24_H12.C Version Horizontal 1.1: For a hard-copy on a BROTHER M-1224L
  15.  * 24 pins printer. (LQ500 compatible). It replaces the 9 pin hard-copy
  16.  * internal (ROM) routine. To be put in the \AUTO folder. This one in
  17.  * horizontal and respects the x/y ratio. Twice the linear size of
  18.  * HC24_H10, good blacks, the best up now, but needs a 128k spooler.
  19.  * R.Hoh 02/01/92
  20.  * Modified 7/2/92 by Ulf RIMKUS (RIMKUS_U@DMRHRZ11.BITNET) for Turbo-C
  21.  * Recompiled 7/2/92 by Ulf RIMKUS with Turbo-C
  22.  */
  23.  
  24. #if defined(__PUREC__)
  25. #include <tos.h>
  26. #include <setjmp.h>
  27. #include <stdio.h>
  28. #include "HC24_H12.h"                   /* Protypes */
  29. #define BC_PRT 0
  30. #define BP _BasPag
  31. #define DUMP_VEC ((long **)0x502)       /* hard-copy vector */
  32. #else
  33. #include <basepage.h>
  34. #include <osbind.h>
  35. #include <bios.h>
  36. #include <xbios.h>
  37. #include <setjmp.h>
  38. #include <types.h>                      /* for size_t type */
  39. #define DUMP_VEC ((long *)0x502)        /* hard-copy vector */
  40. #endif
  41.  
  42. #define N_BYTES 128000L         /* # of data bytes to be sent */
  43.  
  44. #if defined (__PUREC__)
  45. void * pokel (long **address, size_t value);
  46. #else
  47. extern long pokel ();
  48. /*
  49.  * MUST be declared with MWC, even if pokeing
  50.  * is intended to return nothing...
  51.  */
  52. #endif
  53.  
  54. /* macro for peekb in supervisor mode */
  55. #define peekbyte(cp) (*((char *)cp))
  56.  
  57. jmp_buf env;                    /* MUST be global */
  58.  
  59. /*************************************************
  60.  * outputs a char to the printer port (if ready) *
  61.  *************************************************/
  62. void outchar (c)
  63. int     c;              /* Yes, I know, but needed by Bconout()... */
  64. {
  65.     long    ii = N_BYTES;       /* as many as data bytes to be sent */
  66.  
  67.     do {
  68.         if (Bcostat (BC_PRT)) {
  69.             Bconout (BC_PRT, c);
  70.             return;
  71.         }
  72.     } while (ii--);
  73.     longjmp (env, 1);           /* exit : printer/spooler not ready */
  74. }
  75.  
  76. /********************************************************
  77.  * outputs a message to the printer port:               *
  78.  * the 1st byte contains the length of the message      *
  79.  * This is needed 'cause some '\0' may have to be sent  *
  80.  ********************************************************/
  81. void outchars (str)
  82. char   *str;
  83. {
  84.     register    i;
  85.     for (i = 1; i < str[0]; i++)
  86.         outchar (str[i]);
  87. }
  88.  
  89. /*********************
  90.  * hard-copy routine *
  91.  *********************/
  92. void hard_copy () {
  93.  
  94.     static char init_prt[] = {
  95.         10,                     /* # of chars */
  96.         27, '@',                /* Reset printer */
  97.         27, 'l', 5,             /* Left margin */
  98.         27, 'A', 8,             /* define new vertical * space */
  99.         10                      /* LF */
  100.     };
  101.  
  102.     static char line_init[] = {
  103.         6,                      /* # of chars */
  104.         27, '*',                /* Binary mode... */
  105.         39,                     /* ...1440 dots/line */
  106.         0,                      /* # of data = (2 * 640) % 256 */
  107.         5                       /* # of data = (2 * 640) / 256 */
  108.     };
  109.  
  110.     static char next_line[] = {
  111.         3,                      /* # of chars */
  112.         13,                     /* CR */
  113.         10                      /* LF */
  114.     };
  115.  
  116.     static char reset_prt[] = {
  117.         3,                      /* # of chars */
  118.         27, '@'                 /* Reset printer */
  119.     };
  120.  
  121.     static char *screen_base;
  122.     static char masks[] = {
  123.         128, 64, 32, 16, 8, 4, 2, 1
  124.     };
  125.     static char mask2[] = {
  126.         128 + 64, 32 + 16, 8 + 4, 2 + 1
  127.     };
  128.     static char dat[3];
  129.     register char  *pos, data, mask;
  130.     register unsigned   i, drow, col;
  131.     int     prow;
  132.  
  133.     /*** Here comes the hard-copy algo. itself ***/
  134.     if (setjmp (env) == 0) {
  135.         outchars (init_prt);
  136.         screen_base = Physbase ();
  137.         for (prow = 0; prow < 33; prow++) {/* printer rows */
  138.             outchars (line_init);
  139.             for (col = 0; col < 640; col++) {
  140.                 mask = masks[col % 8];
  141.                 pos = screen_base + (prow * 3 * 4 * 80) + (col / 8);
  142.                 for (drow = 0; drow < 3; drow++) {/* data rows */
  143.                     data = 0;   /* clear data */
  144.                     for (i = 0; i < 4; i++) {
  145.         /* pixel = (mask & (peekbyte (pos+(drow * 80 * 4)+(i * 80)))) */
  146.                         if (mask & (peekbyte (pos+(drow * 80 * 4)+(i * 80))))
  147.                             data |= mask2[i];
  148.                     }
  149.                     outchar (data);
  150.                     dat[drow] = data;
  151.                 }
  152.                 for (drow = 0; drow < 3; drow++)/* 2nd data row */
  153.                     outchar (dat[drow]);
  154.             }
  155.             outchars (next_line);/* on the printer */
  156.         }
  157.  
  158.         /*
  159.          * for last printer row, special treatment 'cause
  160.          * there are only 4 screen pixels height to process.
  161.          */
  162.         outchars (line_init);
  163.         for (col = 0; col < 640; col++) {
  164.             mask = masks[col % 8];
  165.             pos = screen_base + (prow * 3 * 4 * 80) + (col / 8);
  166.             data = 0;
  167.             for (i = 0; i < 4; i++) {
  168.                 if (mask & (peekbyte (pos + (i * 80))))
  169.                     data |= mask2[i];
  170.             }
  171.             outchar (data);
  172.             outchar (0);
  173.             outchar (0);
  174.             outchar (data);
  175.             outchar (0);
  176.             outchar (0);
  177.         }
  178.         outchars (reset_prt);
  179.     }
  180. }
  181.  
  182. /****************************************
  183.  *** Here we modify  the  screen-dump ***
  184.  *** vector and let the code residant ***
  185.  ****************************************/
  186. main () {
  187.     pokel (DUMP_VEC, (size_t) hard_copy);/* Modify hc vector */
  188.     Cconws ("\r\n \033p");      /* reverse video ON */
  189.     Cconws ("LQ500 compatible hard-copy routine installed.");
  190.     Cconws ("\033q\r\n ");      /* reverse video OFF */
  191.     Cconws ("Version H1.2 by hohr@cernvax.cern.ch.\r\n");
  192.     /*
  193.      * Terminate and Stay Resident, so the buffers we
  194.      * assigned do not get clobbered by the next process.
  195.      */
  196.     Ptermres ((long) BP -> p_hitpa - (long) BP -> p_lowtpa, 0);
  197.     return 0;                   /* That PureC is satisfied */
  198. }
  199.  
  200. #if defined(__PUREC__)
  201. void * pokel (long **address, size_t value) {
  202.     long    oldstack;
  203.     void * old_vec;
  204.  
  205.     oldstack = Super (0L);
  206.     old_vec = *address;
  207.     *address = (void *) value;
  208.     Super ((void *) oldstack);
  209.     return (old_vec);
  210. }
  211. #endif
  212.  
  213. > End of file HC24_H12.C
  214.  
  215.